package com.project.service.impl;

import com.project.bean.UserBean;
import com.project.mapper.IUserMapper;
import com.project.service.IUserService;

public class UserServiceImpl extends BaseService implements IUserService {
    @Override
    public void addUser(UserBean user, int[] gradeArray) {
        IUserMapper mapper = session.getMapper(IUserMapper.class);
        mapper.addUser(user);
        mapper.addGrade(user.getId(),gradeArray);
        this.commitAndClose();
    }

    @Override
    public void delUser(int id) {
        IUserMapper mapper = session.getMapper(IUserMapper.class);
        mapper.delUser(id);
        this.commitAndClose();
    }

    @Override
    public void update(int id, int[] gradeArray) {
        IUserMapper mapper = session.getMapper(IUserMapper.class);
        mapper.update(id,gradeArray);
        this.commitAndClose();
    }

    @Override
    public UserBean findByIdIncludeGrade(int id) {
        IUserMapper mapper = session.getMapper(IUserMapper.class);
        UserBean user =  mapper.findByIdIncludeGrade(id);
        this.commitAndClose();
        return user;
    }
    public static void main(String[] args){
        IUserService service =new UserServiceImpl();
//        service.addUser(new UserBean("罗杰"),new int[]{1,2,3});
//        service.delUser(9);
//        service.update(1,new int[]{2,3,5,4});
        System.out.println(service.findByIdIncludeGrade(2));
    }
}
